#!/usr/bin/env python
# -*- coding: utf-8 -*-
from sets import Set

triangleSet = Set()

def createTriangleWordDict():
    for n in range(1,50):
        t_n= n*(n+1)/2
        #print t_n
        triangleSet.add(t_n)
    

def wordNumValue(word):    
    wordVal=0
    for letter in list(word):        
        wordVal=wordVal+ord(letter)-64        
    return wordVal

createTriangleWordDict()
        

transactionsFile = open("words.txt", 'r+')
lineArr=[]        
for line in transactionsFile:    
    lineArr.append(line.split(','))

shavedLines=[]
for word in lineArr[0]:
    shavedLines.append(word.replace('"',''))

countTriWords=0   
for word in shavedLines:
    if wordNumValue(word) in triangleSet:
        #print word
        countTriWords=countTriWords+1

print countTriWords, "are Triangle Words"





